$.extend({
    cc:{
        layer:getTopWindow().layer,
        alert:function(){
            var _this =  this;
            var msg = arguments[0];
            var callback = isNotEmpty(arguments[1]) && isFunction(arguments[1])?arguments[1]:arguments[2];
            var options = isNotEmpty(arguments[1]) && !isFunction(arguments[1])?arguments[1]:arguments[2];
            var opts = {
                icon: 1,
                offset:"30%"
            };
            $.extend(true,opts,options);
            _this.layer.alert(msg,opts,function(index){
                if(callback){
                    callback.call(null);
                }
                _this.layer.close(index);
            });
        },
        close:function(index){
            var _this =  this;
            _this.layer.close(index);
        },
        confirm : function(msg,callbackOk,callbackCancel,options){
            var _this =  this;
            var opts = {
                icon: 1,
                offset:"30%"
            };
            $.extend(true,opts,options);
            _this.layer.confirm(msg, opts, function(index){
                if(callbackOk){
                    callbackOk.call(null);
                }
                _this.layer.close(index);
            }, function(index){
                if(callbackCancel){
                    callbackCancel.call(null);
                }
                _this.layer.close(index);
            });
        },
        prompt:function(msg,type,callback){
            var _this =  this;
            _this.layer.prompt({
                title: msg,
                formType: type
            }, function(ok){
                if(callback){
                    callback.call(null,ok);
                }
            });
        },
        tips:function(msg,selector,options){
            var _this =  this;
            var opts = {
                tips: [1, '#3595CC'],
                time: 4000
            };
            $.extend(opts,options);
            _this.layer.tips(msg,selector,opts);
        },
        load:function(type){
            var _this =  this;
            return _this.layer.load(type, {shade: 0.3,time:10*1000});
        },
        open:function(options){
            var _this =  this;
            var defaultConfig ={
                type : 2, //page层
                area : [  '1100px', "600px" ],
                offset: [ '50px'],
                shadeClose:true,
                moveType : 0,
                maxmin : true,
                shade : 0.3,
                success: function(layero, index){
                    var win = getTopWindow();
                    var iframeWin = win[layero.find('iframe')[0]['name']];
                    iframeWin['p_Win'] = window;
                    iframeWin['p_index'] = index;
                }
            };
            var opts = $.extend(defaultConfig,options);
            _this.layer.open(opts);
        },
        ajaxRequest:function(param,options){
            var opt = {
                type: "POST",
                beforeSend:function(){
                    return true;
                },
                async : true,
                contentType:'application/x-www-form-urlencoded',
                dataType : 'text',
                successHandler:function(result){
                }
            };

            $.extend(opt,options);
            var url = basePath + "/callService";
            if(isNotEmpty(opt.url)){
                url = opt.url;
            }
            var type = opt.type;
            var data = {
                "param":param.toJSONString()
            };
            var dataType = opt.dataType;
            var contentType = opt.contentType;
            var async = opt.async;
            var beforeSend = opt.beforeSend;
            var successHandler = opt.successHandler;
            var succFailHandler = opt.succFailHandler;
            var res=0;
            if(isEmpty(url)){
                return;
            }
            var  ajax_index = $.cc.load(2);
            $.ajax({
                type: type,
                url:url,
                data: data,
                dataType: dataType,
                contentType: contentType,
                timeout:60000,
                async : async,
                beforeSend: beforeSend,
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.cc.close(ajax_index);
                },
                success: function (responseText) {
                    $.cc.close(ajax_index);
                    var result = JSonDtoModel.restore(responseText);

                    var state = result.getState();
                    var info = result.getInfo();

                    if(state == 0){
                        if(!async) {
                            res =  successHandler.call(window,result);
                        }else{
                            successHandler.call(window,result);
                        }
                    }else{
                        if(isEmpty(succFailHandler)){
                            info = isEmpty(info)?"空指针异常":info;
                            $.cc.alert(info);
                            return;

                        }else{
                            succFailHandler.call(window,result);
                        }
                    }
                }
            });
            if(!async) {
                return res;
            }
        }
    }
});